package com.xiyou.luckdraw.common.utils;

import org.apache.commons.lang3.StringUtils;

import java.util.UUID;

/**
 * @ClassName: FileUtils
 * @Description: 文件工具类
 * @author: limingxing
 * @Date: 2019-10-10 19:54
 */
public class FileUtils {

    /**
     * 获取uuid的文件名
     *
     * @param suffix
     * @auther Jiangshijian
     * @date 2019-02-18 19:01
     */
    public static String getUuidFileName(String suffix) {
        if (suffix.startsWith(".")) {
            return UUID.randomUUID().toString() + suffix;
        }
        return UUID.randomUUID().toString() + "." + suffix;
    }

    public static String getSuffix(String fileName) {
        int index = fileName.lastIndexOf(".");
        if (StringUtils.isNotBlank(fileName) && index > 0) {
            return fileName.substring(fileName.lastIndexOf("."));
        }
        return null;
    }

}
